package com.smart.parking.service.impl;


import com.smart.parking.service.NoticeService;
import com.smart.parking.service.ViolationService;
import com.smart.parking.utils.PageUtils;
import com.smart.parking.utils.Query;
import com.smart.parking.vo.NoticeVO;
import com.smart.parking.vo.ViolationVO;
import org.dozer.Mapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.smart.parking.mapper.ViolationMapper;
import com.smart.parking.entity.ViolationEntity;



@Service("violationService")
public class ViolationServiceImpl extends ServiceImpl<ViolationMapper, ViolationEntity> implements ViolationService {

    @Autowired
    private Mapper dozerMapper;

    @Autowired
    private NoticeService noticeService;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<ViolationEntity> page = this.page(
                new Query<ViolationEntity>().getPage(params),
                new QueryWrapper<ViolationEntity>()
        );

        return new PageUtils(page);
    }

    /**
     * 添加违规信息
     *
     * @param violationVO 违反签证官
     */
    @Override
    public void addViolation(ViolationVO violationVO) {
        ViolationEntity violationEntity = dozerMapper.map(violationVO, ViolationEntity.class);
        baseMapper.insert(violationEntity);
    }

    /**
     * 添加公告
     *
     * @param noticeVO 公告信息
     */
    @Override
    public void addNotice(NoticeVO noticeVO) {
        //更新处理状态
        ViolationEntity violationEntity=noticeVO.getViolationEntity();
        violationEntity.setHandle(1);
        baseMapper.updateById(violationEntity);
        //发布公告
        noticeService.addNotice(noticeVO);
    }

}
